USE [Condominio]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_vivienda_residente]') AND parent_object_id = OBJECT_ID(N'[dbo].[vivienda]'))
ALTER TABLE [dbo].[vivienda] DROP CONSTRAINT [FK_vivienda_residente]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_reserva_area]') AND parent_object_id = OBJECT_ID(N'[dbo].[reserva]'))
ALTER TABLE [dbo].[reserva] DROP CONSTRAINT [FK_reserva_area]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_reserva_residente]') AND parent_object_id = OBJECT_ID(N'[dbo].[reserva]'))
ALTER TABLE [dbo].[reserva] DROP CONSTRAINT [FK_reserva_residente]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_cuota_vivienda]') AND parent_object_id = OBJECT_ID(N'[dbo].[cuota]'))
ALTER TABLE [dbo].[cuota] DROP CONSTRAINT [FK_cuota_vivienda]
GO

/****** Object:  Table [dbo].[cuota]    Script Date: 07/23/2011 01:47:40 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cuota]') AND type in (N'U'))
DROP TABLE [dbo].[cuota]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[vivienda]') AND type in (N'U'))
DROP TABLE [dbo].[vivienda]
GO


/****** Object:  Table [dbo].[cuota]    Script Date: 07/23/2011 01:47:40 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[cuota]') AND type in (N'U'))
DROP TABLE [dbo].[cuota]
GO

CREATE TABLE [dbo].[cuota](
	[numero] [int] NOT NULL,
	[vivienda] [nchar](10) NOT NULL,
	[periodo] [nchar](10) NOT NULL,
	[importe] [decimal](18, 0) NOT NULL,
	[vencimiento] [datetime] NOT NULL,
	[estado] [bit] NOT NULL,
	[fecPago] [datetime] NULL,
	[formaPago] [varchar](50) NULL,
 CONSTRAINT [PK_Cuota] PRIMARY KEY CLUSTERED 
(
	[numero] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

/****** Object:  Table [dbo].[reserva]    Script Date: 07/23/2011 01:50:43 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reserva]') AND type in (N'U'))
DROP TABLE [dbo].[reserva]
GO

USE [Condominio]
GO

/****** Object:  Table [dbo].[reserva]    Script Date: 07/23/2011 01:50:44 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[reserva](
	[numero] [nchar](10) NOT NULL,
	[fecha] [datetime] NOT NULL,
	[personas] [int] NOT NULL,
	[residente] [nchar](8) NOT NULL,
	[area] [nchar](10) NOT NULL,
	[comentario] [nvarchar](100) NULL,
 CONSTRAINT [PK_Reserva] PRIMARY KEY CLUSTERED 
(
	[numero] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

/****** Object:  Table [dbo].[usuario]    Script Date: 07/23/2011 01:51:43 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[usuario]') AND type in (N'U'))
DROP TABLE [dbo].[usuario]
GO

/****** Object:  Table [dbo].[usuario]    Script Date: 07/23/2011 01:51:43 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[usuario](
	[codigo] [nchar](10) NOT NULL,
	[nombres] [nvarchar](50) NOT NULL,
	[apellidos] [nvarchar](50) NOT NULL,
	[clave] [nvarchar](50) NOT NULL,
	[tipo] [nchar](20) NOT NULL,
 CONSTRAINT [PK_Usuario] PRIMARY KEY CLUSTERED 
(
	[codigo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


USE [Condominio]
GO

/****** Object:  Table [dbo].[area]    Script Date: 07/23/2011 01:47:30 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[area]') AND type in (N'U'))
DROP TABLE [dbo].[area]
GO

USE [Condominio]
GO

/****** Object:  Table [dbo].[area]    Script Date: 07/23/2011 01:47:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[area](
	[codigo] [nchar](10) NOT NULL,
	[tipo] [nchar](10) NOT NULL,
	[ubicacion] [nchar](10) NOT NULL,
	[capacidad] [int] NOT NULL,
	[estado] [nchar](10) NOT NULL,
 CONSTRAINT [PK_Area] PRIMARY KEY CLUSTERED 
(
	[codigo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


/****** Object:  Table [dbo].[residente]    Script Date: 07/23/2011 01:51:19 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[residente]') AND type in (N'U'))
DROP TABLE [dbo].[residente]
GO

USE [Condominio]
GO

/****** Object:  Table [dbo].[residente]    Script Date: 07/23/2011 01:51:19 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[residente](
	[dni] [nchar](8) NOT NULL,
	[nombres] [nvarchar](50) NOT NULL,
	[apellidos] [nvarchar](50) NOT NULL,
	[edad] [int] NOT NULL,
	[correo] [nvarchar](50) NULL,
	[clave] [nvarchar](50) NOT NULL,
	[tipo] [nvarchar](50) NOT NULL
 CONSTRAINT [PK_Residente] PRIMARY KEY CLUSTERED 
(
	[dni] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO


/****** Object:  Table [dbo].[vivienda]    Script Date: 07/23/2011 01:52:08 ******/

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[vivienda](
	[codigo] [nchar](10) NOT NULL,
	[ubicacion] [nvarchar](50) NOT NULL,
	[numero] [int] NOT NULL,
	[metraje] [decimal](18, 0) NOT NULL,
	[tipo] [nchar](50) NOT NULL,
	[residente] [nchar](8) NOT NULL,
	[propietario] [nchar](8) NOT NULL,
 CONSTRAINT [PK_Vivienda] PRIMARY KEY CLUSTERED 
(
	[codigo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
ALTER TABLE [dbo].[vivienda]  WITH CHECK ADD  CONSTRAINT [FK_vivienda_residente] FOREIGN KEY([residente])
REFERENCES [dbo].[residente] ([dni])
GO
ALTER TABLE [dbo].[vivienda] CHECK CONSTRAINT [FK_vivienda_residente]
GO
ALTER TABLE [dbo].[vivienda]  WITH CHECK ADD  CONSTRAINT [FK_vivienda_residente1] FOREIGN KEY([propietario])
REFERENCES [dbo].[residente] ([dni])
GO
ALTER TABLE [dbo].[vivienda] CHECK CONSTRAINT [FK_vivienda_residente1]
GO


ALTER TABLE [dbo].[cuota]  WITH CHECK ADD  CONSTRAINT [FK_cuota_vivienda] FOREIGN KEY([vivienda])
REFERENCES [dbo].[vivienda] ([codigo])
GO

ALTER TABLE [dbo].[cuota] CHECK CONSTRAINT [FK_cuota_vivienda]
GO

ALTER TABLE [dbo].[reserva]  WITH CHECK ADD  CONSTRAINT [FK_reserva_area] FOREIGN KEY([area])
REFERENCES [dbo].[area] ([codigo])
GO

ALTER TABLE [dbo].[reserva] CHECK CONSTRAINT [FK_reserva_area]
GO

ALTER TABLE [dbo].[reserva]  WITH CHECK ADD  CONSTRAINT [FK_reserva_residente] FOREIGN KEY([residente])
REFERENCES [dbo].[residente] ([dni])
GO

ALTER TABLE [dbo].[reserva] CHECK CONSTRAINT [FK_reserva_residente]
GO

ALTER TABLE [dbo].[area] ADD  CONSTRAINT [DF_area_tipo]  DEFAULT ('') FOR [tipo]
GO

ALTER TABLE [dbo].[area] ADD  CONSTRAINT [DF_area_ubicacion]  DEFAULT ('') FOR [ubicacion]
GO

ALTER TABLE [dbo].[area] ADD  CONSTRAINT [DF_area_capacidad]  DEFAULT ((0)) FOR [capacidad]
GO

ALTER TABLE [dbo].[area] ADD  CONSTRAINT [DF_area_estado]  DEFAULT ('') FOR [estado]
GO

ALTER TABLE [dbo].[cuota] ADD  CONSTRAINT [DF_cuota_vivienda]  DEFAULT ('') FOR [vivienda]
GO

ALTER TABLE [dbo].[cuota] ADD  CONSTRAINT [DF_cuota_periodo]  DEFAULT ('') FOR [periodo]
GO

ALTER TABLE [dbo].[cuota] ADD  CONSTRAINT [DF_cuota_importe]  DEFAULT ((0)) FOR [importe]
GO

ALTER TABLE [dbo].[cuota] ADD  CONSTRAINT [DF_cuota_estado]  DEFAULT ((0)) FOR [estado]
GO

ALTER TABLE [dbo].[reserva] ADD  CONSTRAINT [DF_reserva_personas]  DEFAULT ((0)) FOR [personas]
GO

ALTER TABLE [dbo].[reserva] ADD  CONSTRAINT [DF_reserva_residente]  DEFAULT ('') FOR [residente]
GO

ALTER TABLE [dbo].[reserva] ADD  CONSTRAINT [DF_reserva_area]  DEFAULT ('') FOR [area]
GO

ALTER TABLE [dbo].[reserva] ADD  CONSTRAINT [DF_reserva_comentario]  DEFAULT ('') FOR [comentario]
GO

ALTER TABLE [dbo].[residente] ADD  CONSTRAINT [DF_residente_nombres]  DEFAULT ('') FOR [nombres]
GO

ALTER TABLE [dbo].[residente] ADD  CONSTRAINT [DF_residente_apellidos]  DEFAULT ('') FOR [apellidos]
GO

ALTER TABLE [dbo].[residente] ADD  CONSTRAINT [DF_residente_edad]  DEFAULT ((0)) FOR [edad]
GO

ALTER TABLE [dbo].[residente] ADD  CONSTRAINT [DF_residente_correo]  DEFAULT ('') FOR [correo]
GO

ALTER TABLE [dbo].[residente] ADD  CONSTRAINT [DF_residente_clave]  DEFAULT ('') FOR [clave]
GO

ALTER TABLE [dbo].[residente] ADD  CONSTRAINT [DF_residente_tipo]  DEFAULT ('') FOR [tipo]
GO

ALTER TABLE [dbo].[usuario] ADD  CONSTRAINT [DF_usuario_nombres]  DEFAULT ('') FOR [nombres]
GO

ALTER TABLE [dbo].[usuario] ADD  CONSTRAINT [DF_usuario_apellidos]  DEFAULT ('') FOR [apellidos]
GO

ALTER TABLE [dbo].[usuario] ADD  CONSTRAINT [DF_usuario_clave]  DEFAULT ('') FOR [clave]
GO

ALTER TABLE [dbo].[usuario] ADD  CONSTRAINT [DF_usuario_tipo]  DEFAULT ('') FOR [tipo]
GO

ALTER TABLE [dbo].[vivienda] ADD  CONSTRAINT [DF_vivienda_ubicacion]  DEFAULT ('') FOR [ubicacion]
GO

ALTER TABLE [dbo].[vivienda] ADD  CONSTRAINT [DF_vivienda_numero]  DEFAULT ((0)) FOR [numero]
GO

ALTER TABLE [dbo].[vivienda] ADD  CONSTRAINT [DF_vivienda_metraje]  DEFAULT ((0)) FOR [metraje]
GO

ALTER TABLE [dbo].[vivienda] ADD  CONSTRAINT [DF_vivienda_tipo]  DEFAULT ('') FOR [tipo]
GO

ALTER TABLE [dbo].[vivienda] ADD  CONSTRAINT [DF_vivienda_residente]  DEFAULT ('') FOR [residente]
GO

ALTER TABLE [dbo].[vivienda] ADD  CONSTRAINT [DF_vivienda_propietario]  DEFAULT ('') FOR [propietario]
GO
